import 'package:flutter/material.dart';
import 'dart:async';

enum Option{
  A,B,C
}
class SimpleDialogDemo extends StatefulWidget {
  @override
  _SimpleDialogDemoState createState() => _SimpleDialogDemoState();
}

class _SimpleDialogDemoState extends State<SimpleDialogDemo> {
  String choiceStr = 'Nothing';
  Future _openSimpleDialog() async{
   final choice =   await showDialog(
         context: context,
         builder: (BuildContext context){
                return SimpleDialog(
                       title: Text('SimpleDialog'),
                       children: <Widget>[
                         SimpleDialogOption(
                           child: Text('Optional A'),
                           onPressed:(){
                             Navigator.pop(context, Option.A);
                           },
                         ),
                         SimpleDialogOption(
                           child: Text('Optional B'),
                           onPressed:(){
                             Navigator.pop(context, Option.B);
                           },
                         ),
                         SimpleDialogOption(
                           child: Text('Optional C'),
                           onPressed:(){
                             Navigator.pop(context, Option.C);
                           },
                         ),

                       ],

                );
         }
       
       );

       switch (choice) {
       case Option.A :
         setState(() {
           choiceStr = 'A';
         }); 
         break;
        case Option.B :
         setState(() {
           choiceStr = 'B';
         });
          break;
         case Option.C :
         setState(() {
           choiceStr = 'C';
         });
         break;
       default:
     }
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title:Text('SimpleDialogDemo'),
          elevation: 0.0,
        ),
         body: Container(
         padding: EdgeInsets.all(100),
         child: Column(
         mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[ 
            Text('you choice is $choiceStr')
          ],
         ),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed:_openSimpleDialog,
          child: Icon(Icons.format_list_numbered),
        ),
    );
  }
}